package fr.generali.accueilclient.gwt.client.ui.components.menu.tab;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiConstructor;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

import fr.generali.accueilclient.gwt.client.ui.components.menu.Resources;
import fr.generali.accueilclient.gwt.client.ui.components.menu.tab.TabMenuItemTypeSelector.HeaderTabMenuItemType;

/**
 * Correspond à une ligne du menu.<br>
 * Porte un type qui permet d'adapter son style {@link HeaderTabMenuItemType}.<br>
 */
public class TabMenuItem extends Composite implements HasClickHandlers {

    private static HeaderTabMenuItemUiBinder uiBinder = GWT.create(HeaderTabMenuItemUiBinder.class);

    interface HeaderTabMenuItemUiBinder extends UiBinder<Widget, TabMenuItem> {
    }

    @UiField
    Resources res;

    @UiField
    SimplePanel container;

    @UiField
    Anchor itemTitle;

    @UiConstructor
    public TabMenuItem(HeaderTabMenuItemType type) {
        initWidget(uiBinder.createAndBindUi(this));
        res.style().ensureInjected();
        TabMenuItemTypeSelector.applyType(container, type, res);
    }

    public void setTitle(String title) {
        itemTitle.setHTML(title);
    }

    public HandlerRegistration addClickHandler(ClickHandler clickHandler) {
        return this.addDomHandler(clickHandler, ClickEvent.getType());
    }
}
